package view;

import java.awt.Dimension;

import javax.swing.GroupLayout;
import javax.swing.GroupLayout.ParallelGroup;
import javax.swing.JButton;
import javax.swing.JCheckBox;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JList;
import javax.swing.JMenu;
import javax.swing.JMenuBar;
import javax.swing.JMenuItem;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JSplitPane;
import javax.swing.JTabbedPane;
import javax.swing.JTextArea;
import javax.swing.JTextField;
import javax.swing.ListSelectionModel;
import javax.swing.WindowConstants;
import javax.swing.GroupLayout.SequentialGroup;

import model.Patient;

public class MainFrame {
	
	private JFrame mainFrame;
	
	//Menu thingies
	private JMenuBar theMenuBar;
	private JMenu fileMenu, helpMenu;
	private JMenuItem exitProgram, about;

	private JTabbedPane tabbedPane;
	private PatientTab patientTab;
	private SearchTab searchTab;
	
	//Line seperator for strings
	private String newline = System.getProperty("line.separator");
	
	public MainFrame(String[] patients) {
		//creating the frame
		mainFrame = new JFrame("C.I.R.T");
		mainFrame.setExtendedState(JFrame.MAXIMIZED_BOTH);
		mainFrame.setMinimumSize(new Dimension(800,600));
		
		initiateComponents(patients);
		addMenuBar();

		mainFrame.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
		mainFrame.setVisible(true);
	}

	private void initiateComponents(String[] patients) {
		tabbedPane = new JTabbedPane();
		
		//add the patientTab
		patientTab = new PatientTab(patients);
		tabbedPane.addTab("Patient Entries", patientTab);
		
		//add the searchPane to a tab
		searchTab = new SearchTab();
		tabbedPane.addTab("Webcrawler", searchTab);
		
		//set the tabbedPane as contentpane
		mainFrame.setContentPane(tabbedPane);
	}

	/**
	 * Method to create the menu bar, menus and menu items
	 */
	private void addMenuBar() {
		//create & add menubar
		theMenuBar = new JMenuBar();
		mainFrame.setJMenuBar(theMenuBar);
		
		//create & add menus
		fileMenu = new JMenu("File");
		helpMenu = new JMenu("Help");
		theMenuBar.add(fileMenu);
		theMenuBar.add(helpMenu);
		
		//create menuitems
		exitProgram = new JMenuItem("Exit");
		about = new JMenuItem("About");
		fileMenu.add(exitProgram);
		helpMenu.add(about);	
	}
	
	/**
	 * Popup message called when some1 clicks the "about" button
	 */
	public void aboutMessage() {
		JOptionPane.showMessageDialog(mainFrame, "C.I.R.T (Clinical Information Retrieval Tool)" + newline + "is a Safety Reporting IR tool for integrating" + newline + "retrieval processes in clinical databases" + newline + "and subject related resources on the" + newline + "Internet." +
						newline + newline + "Version: 0.0001", "About", JOptionPane.INFORMATION_MESSAGE);
	}
	
	public JMenuItem getAbout() {
		return about;
	}

	public PatientTab getPatientTab() {
		return patientTab;
	}
	
	public SearchTab getSearchTab() {
		return searchTab;
	}
	
	public JTabbedPane getTabbedPane() {
		return tabbedPane;
	}

	public JMenuItem getexitMenuItem() {
		return exitProgram;
	}


}
